from fastai.vision import *
classes = ['With-Mask','WithOut-Mask']
path=Path('storage/data/mask')
path.ls()
np.random.seed(42)
data = ImageDataBunch.from_folder(path, train='.', valid_pct=0.2,
ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)
data.classes
data.show_batch(rows=3, figsize=(7,8))
data.classes, data.c, len(data.train_ds), len(data.valid_ds)
learn = cnn_learner(data, models.resnet34, metrics=error_rate)
learn.fit_one_cycle(2, max_lr=slice(3e-5,3e-4))
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(6, max_lr=slice(3e-2,3e-1))
learn.lr_find()
learn.recorder.plot(),
learn.recorder.plot_lr(show_moms=True)
learn.recorder.plot_losses()
learn.fit_one_cycle(4, max_lr=slice(3e-3,3e-2))
interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix()
learn.export()
defaults.device = torch.device('cpu')
img = open_image(path/'3.jpg')
img
learn = load_learner(path)
pred_class,pred_idx,outputs = learn.predict(img)
pred_class ,